﻿using Shumei.EFCore.Model;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Shumei.EFCore.SimpleService
{
    public class CourseVideoService : BaseSimpleDAL<CourseVideo>
    {
        public CourseVideoService()
        {
 
        }
        public CourseVideo Find(int id)
        {
            CourseVideo res;
            try
            {
                res = Entities.Find(id);
            }
            catch 
            {
                res = null;
            }
            return res;
        }

        public List<CourseVideo> List()
        {
            List<CourseVideo> res;
            try
            {
                res = Entities.ToList();
            }
            catch 
            {
                res = new List<CourseVideo>();
            }
            return res;
        }

        public List<CourseVideo> GetCoursesList(int page, out int totalPage, int num = 10)
        {
            List<CourseVideo> res;
            try 
            {
                res = Entities.OrderBy(x => x.Id).Skip((page - 1) * 10).Take(num).ToList();
                totalPage = (Entities.Count() / num) + 1;
            }
            catch
            {
                res = new List<CourseVideo>();
                totalPage = 1;
            }
            return res;
        }
        public CourseVideo GetCourseVideoDetail(int id)
        {
            try
            {
                return Entities.Find(id);
            }
            catch
            {
                return null;
            }
        }
    }
}
